<!--头部组件-->
<template>
    <div style="display: flex;line-height: 60px;">
        <div style="margin-top: 8px;">
            <!--菜单伸缩-->
            <i :class="icon" style="font-size: 20px;cursor: pointer;" @click="collapse"></i>
        </div>

<!--      文字居中text-align: center，文字大小font-size-->
        <div style="flex: 1;text-align: center;font-size: 34px;">
            <!--欢迎字样-->
            <span>欢迎来到RobotChat！</span>
        </div>

        <el-dropdown>
            <!--dropdown下拉-->
            <!--下拉样式class="el-icon-arrow-down"-->
            <span>{{user.name}}</span><i class="el-icon-arrow-down" style="margin-left: 5px;"></i>
            <el-dropdown-menu slot="dropdown">
                <el-dropdown-item @click.native="toUser">个人中心</el-dropdown-item>
                <el-dropdown-item @click.native="logout">退出登录</el-dropdown-item>
            </el-dropdown-menu>
        </el-dropdown>

    </div>
</template>

<script>
    export default {
        name: "Header",
        data(){
            return {
                user : JSON.parse(localStorage.getItem('CurUser'))
            }
        },
        props:{
            icon:String
        },
        methods:{
            toUser(){
                console.log('to_user')

                this.$router.push("/Home")
            },

            logout(){
                console.log('logout')

                this.$confirm('您确定要退出登录吗？', '提示', {
                    confirmButtonText: '确定',  //确认按钮的文字显示
                    type: 'warning',
                    center: true, //文字居中显示

                })
                    .then(() => {
                        this.$message({
                            type:'success',
                            message:'退出登录成功！'
                        })

                      //路由，跳转登录页面
                        this.$router.push("/")
                      //清空数据
                        localStorage.clear()
                    })
                    .catch(() => {
                        this.$message({
                            type:'info',
                            message:'已取消退出登录！'
                        })
                    })

            },

            collapse(){
                this.$emit('doCollapse')
            }

        },

        created(){
            this.$router.push("/Home")
        }

    }
</script>

<style scoped>

</style>